package com.polylink.sys.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import com.mapper.SqlMapper;
import com.polylink.base.Page;
import com.polylink.sys.bean.Function;
import com.polylink.sys.dao.sqlProvider.FunctionSqlProvider;

/**
 *@author xiliang.xiao
 *@date 2015年3月23日 上午9:03:57
 *
 **/
public interface IFunctionDao extends SqlMapper{

	@Insert("Insert into cti_web_function (name,code,mode_id,remark) "
			+ "value(#{name},#{code},#{modeId},#{remark})")
	public int add(Function function);

	@SelectProvider(type=FunctionSqlProvider.class,method="list")
	public abstract List<Function> list(Page p) ;

	@SelectProvider(type=FunctionSqlProvider.class,method="count")
	public int count(Page p);

	@Update("update cti_web_function set name=#{name},code=#{code},mode_id=#{modeId},remark=#{remark} where id=#{id}")
	public int update(Function function);

	@Delete("delete from cti_web_function where id in (${id})")
	public int delete(@Param("id")String id);

	@Select("SELECT f.`name` fname,f.id,m.id mode_id,m.`name` mname,rf.role_id,m.parent_id FROM cti_web_model m "+
		"LEFT JOIN cti_web_function f on f.mode_id = m.id "+
		"LEFT JOIN cti_web_role_function rf on f.id = rf.function_id and rf.role_id=#{roleId}"+
		"ORDER BY m.parent_id,m.id")
	public List<Map<String, Object>> getFunTree(String roleId);

}
